//
//  Test.swift
//  TestSwift
//
//  Created by 小星星吃KFC on 2021/5/29.
//

import Foundation

struct Test1 {
    
    static  func Test() {
        
        
        class Student: Decodable{
            
            var name : String?;
        }
        
        class Person{
            var student : Student?;
        }
        
        
        
        var map = ["name":"wang","age":"18"]
        
        
        //
        print(map);
        print("bbbb = \(map)")
        
        
        
        
        
        // let jsonData = try JSONSerialization.data(withJSONObject: map, options: [])
        //let model = try JSONDecoder().decode(Student.self, from: jsonData)
        
        
        
        //var name : String?;
        //name = nil;
        //print(name);
        
        //var  p : Person?;
        //
        //Json
        //
        //func test(person : Person){
        //
        //    person = nil;
        //
        //    print(p?.student?.no ?? "jim");
        //
        //}
        ////    test(person: p?? default value);
        
        
        
        struct StudentStruct {
            
            var name : String;
            var age : Int = 0;
            
        }
        
        var arr = [StudentStruct]();
        
        let ss = StudentStruct(name: "jim", age: 10)
        
        arr.append(ss)
        
        print("arr.first = \(String(describing: arr.first))");
        
        
        var ss1 = arr[0];
        ss1.age = 11;
        arr[0] = ss1
        
        print("arr.first 2= \(String(describing: arr.first))");
        
        arr[0].age = 12;
        
        print("arr.first 3= \(String(describing: arr.first))");
        
        print("枚举值================")
        enum Week: String{
            case MON, TUE="2", WED, THU, FRI, SAT, SUN
        }
        
        print(Week.MON)
        print(Week.MON.rawValue)
        print(Week.TUE.rawValue)
        
        
        let num1 = 0.1
        print(num1)
        
        var map1 = [1, 2, 3].map{"index\($0)"}
        
        print("map1 = \(map1)")
        
        var map2 = [1, 2, 3].filter{$0 >= 2}
        print("map2 = \(map2)")
        
        
        var mutableArray = [1,2,3]
        for el in mutableArray {
            print("el = \(el)")
            mutableArray.removeLast()
        }
        print("mutableArray = \(mutableArray)")
        /// reduce 合并
        var map3 = [1, 2, 3].reduce("w"){"el\($0),ad\($1),,"}// 转换为字符串并拼接
        print("map3 = \(map3)")
        
        
        let numbers = [1, 2, 3, 4]
        let numberSum = numbers.reduce(0, { x, y in
            x + y
        })
        print("numberSum = \(numberSum)")
        
        func someFunction() {
            guard true else {
                print("guard = else")
                return
            }
            print("guard = 1")
        }
        someFunction()
        print("guard = 2")
        
        func test2() {
            defer {
                print("\(#function)-end-1-1")
                print("\(#function)-end-1-2")
            }
            
            print("defer = start")
        }
        test2();
        
    }
    
    static  func Test1() {
        
        
    }
}
